/*
 * @lc app=leetcode.cn id=152 lang=javascript
 *
 * [152] 乘积最大子数组
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var maxProduct = function(nums) {
    let ans = -Infinity, mi = 1, mx = 1
    for (let i = 0; i < nums.length; i++) {
        if (nums[i] < 0) {
            let t = mi
            mi = mx
            mx = t
        }
        mx = Math.max(mx * nums[i], nums[i])
        mi = Math.min(mi * nums[i], nums[i])

        ans = Math.max(ans, mx)
    }
    return ans
};
// @lc code=end

